﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace zUpLoad
{
    class cSysStart
    {
        public static string cUserName="demo";
        public static string cUserID = "demo";
        public static string cSysName = "Excel数据导入接口";
        public static string cConnstr = "Data Source=localhost;Initial Catalog=UFDATA_999_2014;User ID=sa;Password=lfy";
        public static DateTime dLoginDate = new DateTime(2000, 1, 1);
        public static string cAccID="001";
        public static string DllName = "zInsertExcel";
        public static DateTime cVerion = new DateTime(2000, 1, 1);

        //public static string cConnstr = "Data Source=server;Initial Catalog=UFDATA_001_2013;User ID=sa;Password=3344wan.";
        public static void  getStartParam()
        {
            int istart = GlobalParameters.gLoginInfo.ConnString.IndexOf("PROVIDER");
            int iend = GlobalParameters.gLoginInfo.ConnString.IndexOf(";", istart);
            string provider = GlobalParameters.gLoginInfo.ConnString.Substring(istart, iend + 1 - istart);
            string nConnStr = GlobalParameters.gLoginInfo.ConnString.Replace(provider, "");
            cSysStart.cConnstr = nConnStr;
            cSysStart.cUserName = GlobalParameters.gLoginInfo.UserName;
            cSysStart.cUserID  = GlobalParameters.gLoginInfo.UserId;
            cSysStart.dLoginDate = DateTime.Parse(GlobalParameters.gLoginInfo.operDate);
            cSysStart.cAccID = GlobalParameters.gLoginInfo.AccID;
            //getDllVersion();
            //return getVersion(cSysStart.DllName);
        }

        //public static void getDllVersion()
        //{
        //    string path=System.Windows.Forms.Application.StartupPath + DllName + ".dll";
        //    if (System.IO.File.Exists(path))
        //    {
        //        object o= Common.cDll.getDllVersion(path);
        //        if (!DateTime.TryParse(o.ToString(), out cSysStart.cVerion))
        //        {
        //            cSysStart.cVerion = new DateTime(2000, 1, 1);
        //        }
        //    }
        //}

        //public static bool  getVersion(string dllname)
        //{
        //    string cmdsql = "select name from ufsystem..syscolumns where id=object_id('ufsystem..zup') order by colorder ";
        //    using (SqlCommand cncmd = new SqlCommand())
        //    {
        //        cncmd.Connection = Common.handleSQL.getConnect();
        //        cncmd.CommandText = cmdsql;
        //        bool bhavetable=false;
        //        bool bneeddrop=false;
        //        DataTable dtjud=new DataTable();
        //        dtjud.Load(cncmd.ExecuteReader());
        //        if(dtjud.Rows.Count !=5 )
        //        {
        //            bhavetable = false;
        //            if (dtjud.Rows.Count > 0)
        //            { bneeddrop = true; }                    
        //        }
        //        else 
        //        {
        //            if (dtjud.Rows[0][0].ToString() == "autoid" &&
        //                dtjud.Rows[1][0].ToString() == "DllName" && dtjud.Rows[2][0].ToString() == "Ver"
        //                && dtjud.Rows[3][0].ToString() == "cFile" && dtjud.Rows[4][0].ToString() == "dUpDate")
        //            { bneeddrop = false; bhavetable = true; }
        //            else { bneeddrop = true; }
        //        }
        //        if( bneeddrop ) 
        //        {
        //            cmdsql="drop table ufsystem..zup";
        //            cncmd.CommandText=cmdsql;
        //            cncmd.ExecuteNonQuery();
        //            bhavetable = false;
        //        }

        //        if( !bhavetable )
        //        {
        //            cmdsql = "create table ufsystem..zup(autoid int identity(1,1) , DllName nvarchar(200),Ver datetime,cFile image,dUpDate datetime)";
        //            cncmd.CommandText = cmdsql;
        //            cncmd.ExecuteNonQuery();
        //        }
        //        cmdsql = string.Format("select max(Ver) from ufsystem..zup where DllName='{0}'", dllname);
        //        cncmd.CommandText = cmdsql;
        //        object  oval = cncmd.ExecuteScalar ();
        //        int ijud;
        //        if (oval != DBNull.Value && oval != null)
        //        {                    
        //            if (DateTime.Parse(oval.ToString()) == cSysStart.cVerion) { ijud = 0; } //正常，返回True
        //            else
        //            {
        //                if (DateTime.Parse(oval.ToString()) < cSysStart.cVerion)
        //                { ijud = 1; } // 需要更新后台数据库的版本号
        //                else //(DateTime)rs[0]>cSysStart.cVerion)
        //                { ijud = 2;  }//系统版本日期大于当前版本，需要更新本地程序
        //            }
        //        }
        //        else { ijud = 3; }//需要更新后台数据库的版本号
        //        switch (ijud)
        //        {
        //            case 0:
        //                return true;
        //            case 1:
        //            case 3:
                        
        //                cmdsql = " insert into ufsystem..zup(Ver) select '" + cSysStart.cVerion.ToString("yyyy-MM-dd") + "'";
        //                cncmd.CommandText = cmdsql;
        //                cncmd.ExecuteNonQuery();
        //                return true;
        //            case 2:
        //            default:
        //                return false;
        //        }



 
        //    }

 
        //}
    }
}
